package com.example.demofdfs.test2;

import java.util.Iterator;

import org.junit.Before;
import org.junit.Test;

import com.example.demofdfs.example.link.DoubleLinked;
import com.example.demofdfs.example.link.Links;

public class LinksTest {

	private Links<String> links;
	
	@Before
	public void init() {
		this.links = new DoubleLinked<>();
		for(int i = 0; i < 10; i++)
			links.add("node- " + i);
	}
	
	@Test
	public void get() {
		System.out.println(links);
		System.out.println(links.get(0));
		System.out.println(links.get(2));
		System.out.println(links.get(links.size() - 1));
		System.out.println(links.get(links.size()));
	}
	
	@Test
	public void remove() {
		System.out.println(links);
		System.out.println(links.remove(0));
		System.out.println(links.remove(2));
		System.out.println(links.remove(links.size() - 1));
		System.out.println(links);
	}
	
	@Test
	public void set() {
		System.out.println(links);
		System.out.println(links.set(0, "node - *"));
		System.out.println(links.set(3, "node - *"));
		System.out.println(links.set(links.size() - 1, "node - *"));
		System.out.println(links);
	}
	
	@Test
	public void iterator_1() {
		Iterator<String> it = links.iterator();
		while(it.hasNext()) 
			System.out.println(it.next());
		System.out.println(links);
	}
	
	@Test
	public void iterator_2() {
		Iterator<String> it = links.iterator();
		while(it.hasNext()) {
			System.out.println(it.next());
			it.remove();
		}
		System.out.println(links);
	}
	
	@Test
	public void iterator_3() {
		Iterator<String> it = links.iterator();
		while(true) {
			System.out.println(it.next());
		}
	}
	
	@Test
	public void iterator_4() {
		Iterator<String> it = links.iterator();
		while(true) {
			it.remove();
		}
	}
}
